<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>修改角色信息</title>
    <th:block th:include="~{common/common::commonHead}"/>
</head>
<body data-width="620" data-height="420">
<div class="container-fluid">
    <div class="container-fluid">
        <form data-auto-set-value="edit" data-get-url="user/getUser" class="form-horizontal" role="form"
              th:action="@{/user/editUser}">
            <input type="hidden" id="userId" name="id">
            <div class="form-group">
                <label class="col-xs-4 control-label"> 用户姓名：</label>
                <div class="col-xs-8">
                    <div class="iconic-input right">
                        <input name="realName" type="text" class="form-control spinner" placeholder="1~20位字符"
                               required minlength="1" maxlength="20">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 control-label"> 用户名：</label>
                <div class="col-xs-8">
                    <div class="iconic-input right">
                        <input name="username" type="text" class="form-control spinner" placeholder="1~20位字符"
                               required minlength="1" maxlength="20">
                    </div>
                </div>
            </div>
            <!--<div class="form-group">-->
                <!--<label class="col-xs-4 control-label"> 用户密码：</label>-->
                <!--<div class="col-xs-8">-->
                    <!--<div class="iconic-input right">-->
                        <!--<input id="password" name="password" type="password" class="form-control spinner"-->
                               <!--placeholder="6~16位字符" required minlength="6" maxlength="20">-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">
                <label class="col-xs-4 control-label"> 所属组织：</label>
                <div class="col-xs-8">
                    <select name="orgId" id="orgId" class="form-control spinner" data-url="org/listOrg"
                            data-value-field="id" data-text-field="orgName" required>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 control-label"> 所属角色：</label>
                <div class="col-xs-8">
                    <select name="roleId" id="roleId" class="form-control spinner" data-url="role/listRole"
                            data-value-field="id" data-text-field="roleName" required></select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 control-label"> 用户状态：</label>
                <div class="col-xs-8">
                    <select name="userStatus" class="form-control spinner" data-url="user/listUserStatus"
                            data-value-field="value" data-text-field="desc" required></select>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
<script>
    var $roleId = $("#roleId");
    $("#orgId").on("change", function () {
        // 先锁住下拉框，防止加载数据时用户更改
        $(this).attr("disabled", true);
        var that = this;
        var value = $(that).val();
        $(this).find("option[value='']").remove();
        $.doAjax("role/listRole", {orgId: value}, function (roleList) {
            $roleId.empty().attr("disabled", false).append($("<option value=''>请选择角色</option>"));
            $roleId.val("");
            roleList.forEach(function (role) {
                var option = $("<option></option>");
                option.attr("value", role.id);
                option.text(role.roleName);
                $("#roleId").append(option);
            });
            $(that).attr("disabled", false);
        });
    });
</script>
